<template id="doudle_pay">
	<div class="doudle_pay">

		<div class="doudle_main" v-if="seen">

			<div class="doudle_main_top"><img src="../../assets/images/my_order/my_order_15.png" />
				<img src="../../assets/images/main/doudle_del.png" @click="total()"/></div>
			<div class="doudle_main_dl">
				<div class="doudle_dl">
					<dl>
						
						<dt><img src="../../assets/images/class/about_coach.png"/></dt>
						<dd>
							<p>教练：{{todos.coach_name}}</p>
							<p>{{todos.class_name}}</p>
							<p>预约时间:{{todos.create_time | formatDate}}</p>
						</dd>
						
					</dl>
				</div>
			</div>

			<div class="doudle_money">
				<div class="doudle_neth">
					<span>应付款: </span>
					<font><span>￥</span>{{todos.price - yuan}}</font>
				</div>
			</div>

			<div class="doudle_detail">
				<div class="doudle_hear">
					<button @click.stop="Money(todos.price,todos.create_time)">立即支付</button>

				</div>
			</div>

		</div>

	</div>
</template>

<script>
	export default {
		data() {

			return {
				seen:true,
				todos: [],
				bookingid:'',
				price:'',
				create_time:'',
				yuan:''
			}

		},
		components: {},
		created() {
			var num=JSON.parse(window.localStorage.getItem('num'))
			console.log(num.coupon)
			this.yuan=Number(num.coupon)
         doudlePay:{
         	//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
			 var	 SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let obj = {
					//请求的参数
					userid: SESSION_ID.user.id,
					sessionid: SESSION_ID.sessionid,	
					bookingid:this.$route.query.bookingid,
				};
				let _this = this
				let qs = require('qs');
		this.$axios.post("http://yogahome.top/yujia/user/findUnpaidBookingByUserId", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
				}).then(function(response) {
					console.log(response.data.data[0].booking)
					if(response.data.data[0].booking== ''){
						_this.seen=false
					}
					_this.todos = response.data.data[0].booking;	
					console.log(response.data.data[0])
					_this.bookingid = response.data.data[0].booking.booking_id
				}).catch(function(error) {
					console.log(error);
				});
         }
		},
		filters: {
			formatDate: function(value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s;
				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
			},
		},
		methods: {
			total() {
				//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
				var	 SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let obj = {
					//请求的参数
					userid: SESSION_ID.user.id,
					bookingid:this.bookingid,
				};
				let _this = this
				let qs = require('qs');
		_this.$axios.post("http://yogahome.top/yujia/booking/cancelBooking", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
			}).then(function(response) {
					console.log(response.data.data)
					if(response.data.code =='1'){
						alert('取消成功')
						_this.seen=false
					}else{
						// _this.seen=false
						
					}
				}).catch(function(error) {
					console.log(error);
				});
				
				_this.$axios.post("http://yogahome.top/yujia/user/findUnpaidBookingByUserId", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
				}).then((response) => {
					_this.todos = response.data.data[0].booking;	
					console.log(response.data.data[0])
					_this.bookingid = response.data.data[0].booking.booking_id
				}).catch((error) => {
					console.log(error);
				});
				
				
			},
			Money(price,create_time){
				
				this.$router.push({
					path:"/pay",
					query:{
						price:this.todos.price,
						create_time:this.todos.create_time,
					}
				})
			}
		},

		computed: {

		}

	}
</script>

<style scoped>
	@import "../../assets/css/doudle_pay.css";
</style>